from selenium import webdriver
import requests
import time
import random
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

"""模拟点击登陆"""

def log_on(url):
    # response = requests.get(url)
    # print(response.status_code)
    driver = webdriver.Chrome()
    driver.get(url)
    time.sleep(random.randint(2, 4))
    a = driver.find_element_by_xpath('//*[@id="hp_nfes_accountbar"]/li[1]/div/button/div')
    a.click()

    # 显示等待
    WebDriverWait(driver, 30, 0.2).until(
        EC.visibility_of_element_located(
            (By.XPATH, '//*[@id="bbz_accounts_pc_lg_box"]/div/div/div[1]/div[1]/form/dl[1]/dd/input')
        )
    )
    b = driver.find_element_by_xpath('//*[@id="bbz_accounts_pc_lg_box"]/div/div/div[1]/div[1]/form/dl[1]/dd/input')
    b.click()
    # driver.execute_script("arguments[0].click();", b)#js点击
    webdriver.ActionChains(driver).send_keys('111').perform()


    time.sleep(1)
    c = driver.find_element_by_xpath('//*[@id="bbz_accounts_pc_lg_box"]/div/div/div[1]/div[1]/form/dl[2]/dd/input')
    webdriver.ActionChains(driver).move_to_element(c).click(c).perform()#鼠标事件点击


    time.sleep(5)


    driver.quit()



if __name__ == '__main__':
    link = 'https://www.ctrip.com/'
    log_on(link)